package com.risk.kernel.service.impl;

import com.risk.common.utils.DateUtils;
import com.risk.kernel.domain.TkTask;
import com.risk.kernel.domain.TkTaskCase;
import com.risk.kernel.mapper.TkTaskMapper;
import com.risk.kernel.service.TkTaskServiceI;
import com.risk.kernel.utils.RandomUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2025/1/2
 * @description:
 */
@Service
public class TkTaskServiceImpl implements TkTaskServiceI {
    @Autowired
    private TkTaskMapper tkTaskMapper;

    /**
     * 查询
     *
     * @param id 主键
     * @return
     */
    @Override
    public TkTask selectTkTaskById(String id) {
        TkTask tkTask = tkTaskMapper.selectTkTaskById(id);
        if (StringUtils.isNotEmpty(tkTask.getDevUseTime())) {
            String[] split = tkTask.getDevUseTime().split("/");
            tkTask.setDevUseTimeArr(split);
        }
        if (StringUtils.isNotEmpty(tkTask.getTestUseTime())) {
            String[] split = tkTask.getTestUseTime().split("/");
            tkTask.setTestUseTimeArr(split);
        }
        return tkTask;
    }

    /**
     * 查询列表
     *
     * @param tkTask
     * @return
     */
    @Override
    public List<TkTask> selectTkTaskList(String keys) {
        return tkTaskMapper.selectTkTaskList(keys);
    }

    /**
     * 新增
     *
     * @param tkTask
     * @return 结果
     */
    @Override
    public int insertTkTask(TkTask tkTask) {
        tkTask.setCreateTime(DateUtils.getNowDate());
        tkTask.setId(RandomUtil.getRandomNumber());
        return tkTaskMapper.insertTkTask(tkTask);
    }

    /**
     * 修改
     *
     * @param tkTask
     * @return 结果
     */
    @Override
    public int updateTkTask(TkTask tkTask) {
        System.out.println();
        return tkTaskMapper.updateTkTask(tkTask);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteTkTaskByIds(String[] ids) {
        return tkTaskMapper.deleteTkTaskByIds(ids);
    }

    /**
     * 删除
     *
     * @param id 主键
     * @return 结果
     */
    @Override
    public int deleteTkTaskById(String id) {
        return tkTaskMapper.deleteTkTaskById(id);
    }

    @Override
    public List<TkTaskCase> getTaskNameList() {
        return tkTaskMapper.getTaskNameList();
    }
}
